#include "types.h"
#include "stat.h"
#include "user.h"

#define MEMORY 64
#define ITERATIONS 1000
#define ALLOCATION 4096
//#define ALLOCATION 4000

int
main(int argc, char *argv[])
{
	int cid = 1;
	int pid;
	int i,j;

	for(i = 0; i < 10; i++){
		pid = fork();
		if(pid == 0){
			printf(1, "child %d is starting\n", cid);
			for(j = 0; j < ITERATIONS; j++){
				if((j % 200) == 0)
					printf(1, "child %d is in iteration %d\n", cid, j);
				sleep(1);
				//printf(1, "child %d woke up\n", children[i]);
				if(cid % 2 == 0){
					malloc(1);
					//printf(1, "child %d malloced 1\n", children[i]);
				}
			}
			printf(1, "child %d is exiting\n", cid);
			exit();
		}
		cid++;
	}

	int pid2;
	for(i = 0; i < 10; i++){
		pid2 = wait();
		printf(1, "parent finished waiting for child with pid %d\n", pid2);
	}
	exit();
}
